home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / SPX20.ZIP / SPX_DOC.ZIP / SPX_ES.DOC < prev    next >
Text File  |  1993-09-16  |  5KB  |  151 lines

  1. { SPX Library Version 2.0  Copyright 1993 Scott D. Ramsay }
  2.  
  3.  SPX_ES allows a simplified method to load sprites in expanded memory.
  4.  Turbo Vision's Objects unit is required.
  5.  
  6. ───────────────────────────────────────────────────────────────────────────
  7.  
  8.  Before one would load sprites into main memory by doing the following:
  9.  
  10.    var
  11.      sprites : array[1..MaxSprites] or pointer;
  12.    begin
  13.      loadVSP('myspr.vsp',sprites);      { load the sprites }
  14.      fput(100,100,sprites[1]^,false);   { display the 1st sprite on screen }
  15.    end;
  16.  
  17.  This unit's method is very similar except first you have to create a global
  18.  expanded memory area to contain all the sprite data for the program.
  19.  
  20.    const
  21.      maxSize = 200000;   { about 200k of sprites need to be loaded }
  22.  
  23.    var
  24.      emsGlobalmem : PEmsStack;
  25.  
  26.    emsGlobalmem := CreateEmsStack(maxSize);
  27.  
  28.  The function CreateEmsStack allocates expanded memory and returns a pointer
  29.  type for that area.  If the area could not be allocated, then the function
  30.  returns NIL.
  31.  
  32.  Once the memory area is created, you just load the sprites just like
  33.  before except the sprite array must be of type PEmsDyData.
  34.  
  35.      var
  36.        sprites : array[1..MaxSprites] or PEmsDyData;
  37.      begin
  38.        StackLoadVSP('myspr.vsp',sprites,emsGlobalmem,false);
  39.        fput(100,100,vp(sprites[1])^,false);   { display the 1st sprite on screen }
  40.      end;
  41.  
  42.  
  43.  StackLoadVSP takes two new arguments compared to LoadVSP.
  44.  
  45.  You pass in the pointer to the expanded memory area and a boolean value.
  46.  If the boolean value is set to TRUE it forces StackLoadVSP to load the
  47.  sprites in regular heap space.  This way you can automate the load:
  48.  
  49.    StackLoadVSP('myspr.vsp',sprites,emsGlobalmem,(emsGlobalmem=nil));
  50.  
  51.  If emsGlobalmem could not be allocated, then the sprites are loaded to
  52.  regular memory.
  53.  
  54.  Notice in the fput procedure we call the function VP.  The function Vp
  55.  accesses the expanded memory and returns an ACTUAL pointer to the sprite
  56.  data.
  57.    This pointer can point to the temporary buffer created by the unit.  By
  58.  default the unit allocates 16k of memory as a temporary buffer.  If you
  59.  want to change the buffer size, call the procedure ChangeTempBuffer.
  60.    The temporary buffer should be the same size or larger than the largest
  61.  sprite loaded.
  62.  
  63.  
  64.  At the end of your program you must call the DeleteEmsStack procedure to
  65.  deallocate your ems global memory.  Since exiting a program does not free
  66.  expanded memory.
  67.  
  68. ───────────────────────────────────────────────────────────────────────────
  69. function CreateEmsStack(size:longint):PEmsStack;
  70.  
  71.     Allocates ems global memory.
  72.  
  73.     SIZE:   Size of the memory to allocate
  74.  
  75.     Returns: A pointer that describes the allocated memory area or NIL
  76.              if it could not allocate the memory
  77.  
  78. ───────────────────────────────────────────────────────────────────────────
  79. procedure DeleteEmsStack(var p:PEmsStack);
  80.  
  81.     Deallocate ems global memory.
  82.  
  83.     P: A pointer to the ems memory structure
  84.  
  85.      At the end of your program you must call this procedure to
  86.  deallocate your ems global memory.  Since exiting a program does not free
  87.  expanded memory.
  88.  
  89. ───────────────────────────────────────────────────────────────────────────
  90. function AddEmsStack(var p:PemsStack;var data;size:word):boolean;
  91.  
  92.     Adds custom data to the ems memory area.
  93.  
  94.     P:      A pointer to the ems memory structure
  95.     DATA:   Data to copy to ems memory
  96.     SIZE:   Size of the data to copy
  97.  
  98.     Returns  TRUE if successful, else returns FALSE if memory area is
  99.       full or other error
  100.  
  101.    Note:
  102.       The actual position of the data  can be found by following:
  103.  
  104.        ok := AddEmsStack(emsMem,data,dataSize);
  105.        if ok
  106.          then dataposition := emsMem^.flocator-dataSize;
  107.  
  108. ───────────────────────────────────────────────────────────────────────────
  109. function ReadEmsStack(var p:PemsStack;position:longint;var data;size:word):boolean;
  110.  
  111.     Retreives data from ems memory area.
  112.  
  113.     P:         A pointer to the ems memory structure
  114.     POSITION:  Offset to start reading
  115.     DATA:      Data array to get the ems memory
  116.     SIZE:      Size of the data to copy
  117.  
  118.     Returns TRUE if successful
  119.  
  120. ───────────────────────────────────────────────────────────────────────────
  121. procedure ChangeTempBuffer(size:word);
  122.  
  123.     Changes the temporary buffer
  124.  
  125.     SIZE:  Size to change temporary buffer
  126.  
  127. ───────────────────────────────────────────────────────────────────────────
  128. procedure StackLoadVSP(fn:string;var buff;var p:PEmsStack;loadlow:boolean);
  129.  
  130.    Loads sprites to main memory or expanded memory
  131.  
  132.    FN:      VSP file name
  133.    BUFF:    a PEmsDyData structure.  Can be a single pointer or an array
  134.             of PEmsDyData.
  135.    P:       A pointer to the ems memory structure to place the sprites
  136.    LOADLOW: Set to TRUE to force to load in main memory
  137.  
  138.    Sets the variable vspcnt to the number of sprites loaded.
  139.  
  140.    Note:  When the allocated ems memory becomes full or can not be reached,
  141.    the rest of the sprites are loaded to main memory.
  142.  
  143. ───────────────────────────────────────────────────────────────────────────
  144. function vp(var p:PEmsDyData):pointer;
  145.  
  146.    Returns a pointer to the data specfied by the PEmsDyData structure.
  147.  
  148.    P: A pointer to the ems memory structure
  149.  
  150. ───────────────────────────────────────────────────────────────────────────
  151.